package com.ztesoft.huangfu.learning.springboot.springbootwebflux.config;

import com.ztesoft.huangfu.learning.springboot.springbootwebflux.service.CityService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/6/13
 * Time: 10:11
 * Version: 1.0
 * Description:
 **/
@Configuration
public class Routes {
    private CityService cityService;

    public Routes(CityService cityService) {
        this.cityService = cityService;
    }

    // RoouterFunction 类似 Spring Web MVC 的 @RequestMapping ，
    // 用来定义路由信息，每个路由会映射到一个处理方法，当接受 HTTP 请求时候会调用该处理方法
//    @Bean
//    public RouterFunction<?> routerFunction() {
//        return route(
//                GET("/api/city")
//                        .and(accept(MediaType.APPLICATION_JSON)), cityService::findAllCity)
//                .and(route(
//                GET("/api/user/{id}")
//                        .and(accept(MediaType.APPLICATION_JSON)), cityService::findCityById)
//        );
//    }
}
